<template>
	<view class="content">
		<navigator  v-if="!token" url="/pages/login/index">
			<button  style="margin-top: 50vh;background-color: skyblue;color: aliceblue;" class='bottom' >
					  微信一键授权登录
			</button>   
			
			<button @click="navPsdLogin" style="margin-top: 50upx;background-color: rgb(15, 108, 243);color: aliceblue;" class='bottom' >
					  账号密码登录
			</button>   
		</navigator>
		 <view v-else @longpress="tuichu" style="margin-top:50vh;font-size: 48upx;">
		 	welcome
		 </view>
		 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				token:"",
			}
		},
		onLoad() {

		},
		onShow() {
			// if(uni.getStorageSync("token")){
			// 	uni.switchTab({
			// 		url: '/pages/quick/index'
			// 	});
			// }
			this.token=!uni.getStorageSync("token")?"":uni.getStorageSync("token")
			this.$forceUpdate() //强制渲染
			
		},
		
		methods: {
			getphonenumber (e){
				console.log(123,e.detail)
				if(e.detail){
					this.getOpenId(e.detail.code)
				}else{
					uni.navigateBack()
				}
				
			},
			navPsdLogin(){
				uni.navigateTo({
					url:"/pages/login/psdLogin"
				})
			},
			tuichu(){
				uni.showModal({
					title: '登录提示',
					content: '是否退出登录',
					// showCancel: false,
					success(res) {
						if (res.confirm) {
							uni.removeStorageSync("token")
							uni.switchTab({
								url: '/pages/home/index'
							});
						}else if (res.cancel) {
						}
						
					}
				})
			},
			getOpenId (code){
				if(code){
					console.log(123,code)
					var that=this
					uni.login({
						success :async function(res) {
							
							// console.log(res.code,code)
							// console.log(123)
							// const getProgrammeById = await that.$ajax.getProgrammeById({
							// 	id:27
							// })
							// console.log(321)
							
							const newLoginss = await that.$ajax.newLogin({
								code: res.code,
								phoneCode: code
							})
							
							console.log(newLoginss)
							
							uni.setStorageSync('token', newLoginss.data.data.token);
							uni.setStorageSync('userinfo',newLoginss.data.data.userinfo);
							
							uni.navigateBack({
								fail(){
									uni.switchTab({
										url:"/pages/home/index"
									})
								}
							});
							
						}
					})
				}
				
				// newLongin
				// newLogin
				// const newLogin = await this.$ajax.newLogin({
				// 	code: code,
				// 	phoneCode: that.phoneCode
				// })
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.text{
		color: #313131;
		font-size: 22px;
		font-family: HarmonyOS Sans SC;
		font-weight: 700;
		line-height: 26px;
		/* text-align: center; */
		margin-top: 50px;
		margin-left: 3px;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 100upx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	
	.bottom{
		width: 600upx;
		border-radius: 100upx;
		font-size: 35upx;
		
	}
</style>
